﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web;
using NVSecurity.Models;

namespace NVSecurity.Utility
{
    public class Email
    {
        public NVSecurityEntities db = new NVSecurityEntities();

        //send email đơn giản
        public void SendEmail1(string Emailto, string Emailfrom, string subject, string body, string passmail, string servermail)
        {

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.To.Add(Emailto); //recipient
            message.BodyEncoding = Encoding.UTF8;
            message.Subject = subject;
            message.From = new System.Net.Mail.MailAddress(Emailfrom); //from email

            message.Body = "<html><body><font face='Tahoma,Arial,sans-serif' size='-1'>";
            message.Body += body;
            message.IsBodyHtml = true;

            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(servermail);// you need an smtp server address to send emails
            smtp.Credentials = new System.Net.NetworkCredential(Emailfrom, passmail); //missing line from ur code
            smtp.Send(message);
        }

        //send email có BCC, CC
        public void SendEmail2(string Emailto, string Emailfrom, string subject, string body, string passmail, string servermail)
        {

            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
            message.To.Add(Emailto); //recipient
            message.BodyEncoding = Encoding.UTF8;
            message.Subject = subject;
            message.From = new System.Net.Mail.MailAddress(Emailfrom); //from email

            message.Body = "<html><body><font face='Tahoma,Arial,sans-serif' size='-1'>";
            message.Body += body;
            message.IsBodyHtml = true;

            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(servermail);// you need an smtp server address to send emails
            smtp.Credentials = new System.Net.NetworkCredential(Emailfrom, passmail); //missing line from ur code
            smtp.Send(message);
        }
        public static bool SendMail_By_Gmail(string to, string strSubject, string strContent)
        {

            MailMessage mail = new MailMessage();
            mail.To.Add(to);
            //mail.Bcc.Add(new MailAddress("aaaaaa@gmail.com"));
            mail.Subject = strSubject;
            mail.IsBodyHtml = true;
            mail.Body = strContent;
            mail.From = new MailAddress("minhtristudent@gmail.com");
            SmtpClient client = new SmtpClient();
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = true;
            client.Host = "smtp.gmail.com";
            client.Port = int.Parse("587");
            // khai báo tài khoản và mat khẩu gừi mail
            NetworkCredential credentials = new NetworkCredential("minhtristudent@gmail.com", "0973752768");
            client.UseDefaultCredentials = false;
            client.Credentials = credentials;
            client.Send(mail); // thuc hien gui mail
            return true;


        }
    }
}